import rpg.map.Creature
import rpg.map.MapObject
import rpg.script.SkillScriptImpl

class SkillPhysicalAttack extends SkillScriptImpl {
	private static ArrayList<Integer> strength = new ArrayList<Integer>();
	static {
		strength.add(0, 1);
		strength.add(1, 2);
		strength.add(2, 5);
		strength.add(3, 10);
		strength.add(4, 20);
	}

	// Strength
	@Override
	public Integer getStrength() {
		return strength.get(this.getSkill().getData().getLevel());
	}

	// Use Events
	@Override
	public boolean onUse(MapObject mapObject) {
		if(mapObject.getClass() != Creature.class)
			return false;
		
		Creature creature = (Creature) mapObject;
		if(this.getSkill().getCreature().getLocation().distance(creature.getLocation(), true) > 1) {
			return false;
		}

		// Damage
		Integer[] damage = this.getSkill().getCreature().damage(this.getSkill().getData().getTypes(), getStrength());
		damage[0] -= creature.resistance(this.getSkill().getData().getTypes());

		if(damage[0] <= 0) {
			damage[0] = 1;
		}

		creature.changeHealth(damage[0], damage[1] > 0);
		return true;
	}
}
